#!/bin/bash
# 将cleanup-scripts目录复制到/opt/job
cp -rf /cleanup-scripts /opt/job

# 检查复制是否成功
if [ $? -eq 0 ]; then
  # 删除原始目录
  rm -rf /cleanup-scripts
  echo "移动成功！"
else
  echo "移动失败，请检查权限或其他错误。"
fi
#mv -f /cleanup-scripts /opt/job

(crontab -l ; echo "05 07,13,19,01 * * * sh /opt/job/cleanup-scripts/clean-host-cache.sh >> /opt/job/cleanup-scripts/logs/clean-host-cache.log") | crontab -

(crontab -l ; echo "00 01 * * * sh /opt/job/cleanup-scripts/clean-common-logs.sh  >> /opt/job/cleanup-scripts/logs/clean-common-logs.log") | crontab -


# 获取当前用户的Crontab列表
crontab_list=$(crontab -l)

# 将Crontab列表中的任务按行进行排序并去重
unique_crontab=$(echo "$crontab_list" | awk '!x[$0]++')

# 将去重后的任务重新设置为当前用户的Crontab
echo "$unique_crontab" | crontab -

echo "重复的Crontab任务已删除"




systemctl enable crond
systemctl restart crond
crontab -l

